package com.ihome.android.market2.frag;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.TextureView;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.View.OnFocusChangeListener;
import android.webkit.JavascriptInterface;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.ihome.android.EAApp;
import com.ihome.android.EAFragment;
import com.ihome.android.annotation.EAInjectView;
import com.ihome.android.http.HttpKeys;
import com.ihome.android.image.CubeImageView;
import com.ihome.android.image.ImageLoader;
import com.ihome.android.image.ImageLoaderFactory;
import com.ihome.android.academy.DetailActivity;
import com.ihome.android.academy.R;
import com.ihome.android.academy.VideoFullscreenActivity;
import com.ihome.android.academy.WebViewActivity;
import com.ihome.android.common.ConfigUtil;
import com.ihome.android.market2.info.HomepagecontentEdu;
import com.ihome.android.market2.info.LayoutEdu;
import com.ihome.android.market2.view.BasicWebview;
import com.ihome.android.market2.view.SmallTitle;
import com.ihome.android.util.AppUtils;
import com.ihome.android.util.log.LogUtil;

import com.iptv.player.BasicPlayer;
import com.iptv.player.IPTVPlayer;

/**
 * 设置首页的页面布局：主要分成3部分 1：图片显示 2：视频和点击按钮 3：小标题和图片
 * 
 * @author Administrator
 * 
 */
public class RecommAppFragmentEdu extends EAFragment implements OnClickListener, OnFocusChangeListener, OnKeyListener {
	private String						TAG					= RecommAppFragmentEdu.class.getSimpleName();
	private View						fragview;


	private String						playUrl				= "rtsp://221.228.34.68:554/vod/23380900020010439627.mpg?userid=itvzhengh01&stbip=61.155.239.28&clienttype=1&mediaid=0000000030010009625363&ifcharge=1&time=20150803143724+08&life=172800&usersessionid=31135&vcdnid=vcdn001&boid=001&srcboid=001&columnid=391804&backupagent=221.228.34.68:554&ctype=1&playtype=0&Drm=0&EpgId=null&programid=23380900020010439627&contname=&fathercont=&bp=0&authid=&tscnt=0&tstm=0&tsflow=0&ifpricereqsnd=1&stbid=00100299007011500003C864C79D44D1&nodelevel=3&terminalflag=1&bitrate=0&usercharge=47D3B44B73B209A9CD3BE6DE83553308";
	@EAInjectView(id = R.id.img1)
	private CubeImageView				img1;
	@EAInjectView(id = R.id.img2)
	private CubeImageView				img2;
	@EAInjectView(id = R.id.img3)
	private CubeImageView				img3;
	@EAInjectView(id = R.id.rl_main_right)
	private RelativeLayout				topMainRight;
	@EAInjectView(id = R.id.main_surface)
	private SurfaceView					mSurfaceView;
	@EAInjectView(id = R.id.surface_frame)
	private FrameLayout					fl_surface;
	RelativeLayout.LayoutParams			topMainRParams		= null;
	RelativeLayout.LayoutParams			frameLParams		= null;
	/*	@EAInjectView(id = R.id.videoFrame)
		private MySurfaceView					mFrameSurfaceView;*/
	@EAInjectView(id = R.id.img5)
	private CubeImageView				img5;
	@EAInjectView(id = R.id.img6)
	private CubeImageView				img6;
	@EAInjectView(id = R.id.img7)
	private CubeImageView				img7;
	@EAInjectView(id = R.id.img8)
	private CubeImageView				img8;
	@EAInjectView(id = R.id.img4)
	private CubeImageView				img4;

	//	@EAInjectView(id = R.id.searchCourse)
	//	private TextView					searchCourse;
	//	@EAInjectView(id = R.id.myCourse)
	//	private TextView					myCourse;
	@EAInjectView(id = R.id.latest_recommend)
	private SmallTitle					latest_recommend;
	@EAInjectView(id = R.id.active_area)
	private SmallTitle					active_area;

	@EAInjectView(id = R.id.bsview)
	private BasicWebview				webView;
	private String						specUrl				= null;

	private String						pageName			= "首页";
	private String						pageUrl;
	private int 						flag;
	public boolean isAtRight = false;

	private List<HomepagecontentEdu>	mPosterList;

	private int							focusedPos			= 0;

	/** 加载图片 */
	private ImageLoader					imageLoader;


	public static Handler				mHandler;

	/******* For video play *********/
	public static final int				MSG_VIDEO_PLAY		= 0X01;
	public static final int				MSG_VIDEO_PLAY_END	= 0X02;
	public static final int				MSG_VIDEO_PLAY_STOP	= 0X03;
	private IPTVPlayer					mPlayer;
	private SurfaceHolder				mSurfaceHolder		= null;
	private int							mSurfaceWidth		= -1;
	private int							mSurfaceHeight		= -1;
	/*	private boolean mPlayerReleased = false;
		private boolean mNeedStartPlay = false;*/
	public static int					VideoRetryTime		= 0;
	private boolean						mNeedStartPlay		= false;
	private boolean						mVideoInitialized	= false;
	private boolean						mPlayerReleased		= false;
	private boolean						isLive				= false;

	private List<HomepagecontentEdu> orderEdu;

	private void procHandler() {
		mHandler = new Handler() {
			@Override
			public void handleMessage(Message msg) {
				switch (msg.what) {
				case MSG_VIDEO_PLAY:
					String url = (String) msg.obj;
					VideoRetryTime = 0;

					//					initPlayer();
					mPlayer.stop();
					mPlayer.setProgramURL(url);
					mPlayer.setLive(isLive);
					img4.setVisibility(View.GONE);
					mPlayer.start();
					mNeedStartPlay = false;
					break;
				case MSG_VIDEO_PLAY_END:
					startVideoPlay(playUrl);
					break;
				case MSG_VIDEO_PLAY_STOP:
					mPlayer.stop();
					break;
				}
			}
		};
	}

	@Override
	protected void setFragView() {
		mFragView = fragview;
	}

	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);
		pageName = getArguments().getString(HttpKeys.KEY_SECTIONID, "首页");
		pageUrl = getArguments().getString(HttpKeys.KEY_SPECIALURL, "");
		flag = getArguments().getInt(HttpKeys.KEY_FLAG, 0);
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		procHandler();
		imageLoader = ImageLoaderFactory.create(getActivity());
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		super.onCreateView(inflater, container, savedInstanceState);
		if (flag==0) {
			fragview = inflater.inflate(R.layout.frag_recomm_app_academy_test, container, false);
		}else {
			fragview = inflater.inflate(R.layout.web_view_edu, container, false);
		}
		return fragview;
	}

	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		super.onViewCreated(view, savedInstanceState);

		LogUtil.d(TAG, " --> onViewCreated()  pageName= " + pageName);


		if (flag==0) {
			topMainRParams = (RelativeLayout.LayoutParams) topMainRight.getLayoutParams();
			frameLParams = (RelativeLayout.LayoutParams) fl_surface.getLayoutParams();

			fl_surface.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					if (((RelativeLayout.LayoutParams) topMainRight.getLayoutParams()).height != RelativeLayout.LayoutParams.MATCH_PARENT) {
						RelativeLayout.LayoutParams rLayoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
						topMainRight.setLayoutParams(rLayoutParams);

						RelativeLayout.LayoutParams lParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
						//http://www.67tgb.com/?p=461
						fl_surface.bringToFront();
						fl_surface.setLayoutParams(lParams);
					}else{
						topMainRight.setLayoutParams(topMainRParams);
						fl_surface.setLayoutParams(frameLParams);
					}

				}
			});
			List<HomepagecontentEdu> orderNum = orderNum();
			setData(orderNum);
		}
		else {
			webView.addJavascriptInterface(new JSInterface(this.getActivity()), "android");
			loadSpecUrl(pageUrl);
			
			webView.setOnKeyListener(new OnKeyListener() {
				
				public boolean onKey(View v, int keyCode, KeyEvent event) {

					return false;
				}
			});
		}
	

	}

	int colMin = 1;
	int colMax = 1;
	int rowMin = 1;
	int rowMax = 1;
	int midCol = 1;
	int midRow = 1;
	public List<HomepagecontentEdu> orderNum(){
		orderEdu = new ArrayList<HomepagecontentEdu>();
		for(HomepagecontentEdu edu : EAApp.getApp().mHomeContentEduList){
			LayoutEdu seat = edu.getSeat();

			if(seat.getCol()>colMax){
				colMax = seat.getCol();
			}
			if(seat.getRow()>rowMax){
				rowMax = seat.getRow();
			}
			if(seat.getCol()<colMin){
				colMin = seat.getCol();
			}
			if(seat.getRow()<rowMin){
				rowMin = seat.getRow();
			}
		}	

		int midCol = (colMin+colMax)/2;
		int midRow = (rowMin+rowMax)/2;

		for(HomepagecontentEdu edu : EAApp.getApp().mHomeContentEduList){
			LayoutEdu seat = edu.getSeat();
			if(seat.getRow()==rowMin && seat.getCol()==colMin){
				edu.setPosition(0);
			}
			else if(rowMin==seat.getRow() && seat.getCol()==colMax){
				edu.setPosition(3);
			}else if(seat.getRow()==rowMin){
				edu.setPosition(1);
			}
			else if(rowMax==seat.getRow()){
				if(colMin==seat.getCol()){
					edu.setPosition(4);
				}else if(midCol>seat.getCol() && seat.getCol()>colMin){
					edu.setPosition(5);
				}else if(midCol<seat.getCol() && seat.getCol()<colMax){
					edu.setPosition(6);
				}else if(colMax==seat.getCol()&& seat.getCol()==colMax){
					edu.setPosition(7);
				}
				
			} else if(seat.getRow()!=rowMin && seat.getCol()!=colMax){
				edu.setPosition(2);
			}
			orderEdu.add(edu);
		}

		return orderEdu;
	}

	@Override
	public void onResume() {
		super.onResume();
		LogUtil.d(TAG, " --> onResume() position = " + focusedPos);
		if (flag==0) {
			initVideo();
		}
	}

	@Override
	public void onDestroyView() {
		// TODO Auto-generated method stub
		super.onDestroyView();
		LogUtil.d(TAG, " --> onDestroyView()");

	}
	public void setData(List<HomepagecontentEdu> posterList) {
		mPosterList = posterList;
		initView();
		LogUtil.d(TAG, " --> setData()  = " + posterList.size());
	}

	private void initView() {
		LogUtil.d(TAG, " --> initView() position = " + focusedPos);

		for (HomepagecontentEdu info : mPosterList) {
			if (info.getPosition()== 0) {
				img1.loadImage(imageLoader, info.getPosterpic());
				img1.setTag(info);
			}
			else if (info.getPosition() == 1) {
				img2.loadImage(imageLoader, info.getPosterpic());
				img2.setTag(info);
			}
			else if (info.getPosition() == 2) {
				img3.loadImage(imageLoader, info.getPosterpic());
				img3.setTag(info);
			}
			else if (info.getPosition() == 3) {
				fl_surface.setTag(info);

				//playUrl = info.getPlayUrl();
				img4.setVisibility(View.VISIBLE);
				img4.loadImage(imageLoader, info.getPosterpic());
			}
			else if (info.getPosition() == 4) {
				img5.loadImage(imageLoader, info.getPosterpic());
				img5.setTag(info);
			}
			else if (info.getPosition() == 5) {
				img6.loadImage(imageLoader, info.getPosterpic());
				img6.setTag(info);
			}
			else if (info.getPosition() == 6) {
				img7.loadImage(imageLoader, info.getPosterpic());
				img7.setTag(info);
			}
			else if (info.getPosition() == 7) {
				img8.loadImage(imageLoader, info.getPosterpic());
				img8.setTag(info);
			}
		}
		

		setFocusChange(img1);
		setFocusChange(img2);
		setFocusChange(img3);
		setFocusChange(img5);
		setFocusChange(img6);		
		setFocusChange(img7);
		setFocusChange(img8);
		setFocusChange(fl_surface);

		setFocusChange1(latest_recommend.viewMoreFocus());
		setFocusChange1(active_area.viewMoreFocus());

		if (mSurfaceView == null) {
			LogUtil.d(TAG, " --> mSurfaceView == null");
		}

		latest_recommend.setNameText("最新推荐");
		active_area.setNameText("活动专区");
	}
	public void setFocusChange1(View v) {
		v.setFocusable(true);
		v.setFocusableInTouchMode(true);
		v.setOnFocusChangeListener(this);
		v.setOnKeyListener(this);
	}

	public void setFocusChange(View v) {
		v.setFocusable(true);
		v.setFocusableInTouchMode(true);
		v.setOnFocusChangeListener(this);
		v.setOnClickListener(this);
		v.setOnKeyListener(this);
	}

	private void postClick(HomepagecontentEdu info) {

		//0：应用，1：视频，2：页面，3：页面组合
		if (info.getType() == 0) {
			if (AppUtils.isPkgExist(this.getActivity(), "com.ihome.android.market2")) {
				Intent intent = new Intent("com.ihome.android.market2.DetailActivity");
				intent.addCategory(Intent.CATEGORY_DEFAULT);
				intent.putExtra(HttpKeys.KEY_APPID, Integer.parseInt(info.getAppId()));//测试数据
				getActivity().startActivity(intent);
			}else{
				Toast.makeText(getActivity(), "您没有安装悦市场", 2000).show();
			}
		}
		else if (info.getType() == 1) {
			LogUtil.d(TAG, "info.getType() == 1");
			if (info.getPlayUrl().trim().contains(".m3u8")) {
				Intent intent = new Intent(getActivity(), BasicPlayer.class);
				Bundle b = new Bundle();
				b.putString(ConfigUtil.VIDEO_URL_KEY, info.getPlayUrl());
				intent.putExtras(b);
				getActivity().startActivity(intent);
			}
			else {

//				startVideoPlay(info.getPlayUrl());
//				releasePlayer();
				stopPlayer();
				Intent intent = new Intent(getActivity(), VideoFullscreenActivity.class);
				Bundle b = new Bundle();
//				b.putString(ConfigUtil.VIDEO_URL_KEY, tmpUrl);
				b.putString(ConfigUtil.VIDEO_URL_KEY, info.getPlayUrl());
				intent.putExtras(b);
				getActivity().startActivity(intent);			}
		}
		else if (info.getType() == 2) {
			if(TextUtils.isEmpty(info.getUrl())){
				return;
			}
			Intent intent = new Intent();
			intent.putExtra(HttpKeys.KEY_APPURL, info.getUrl());
			intent.putExtra(HttpKeys.KEY_FLAG,1);
			intent.setClass(this.getActivity(), WebViewActivity.class);
			getActivity().startActivity(intent);
		}
		else if (info.getType() == 3) {
			if(TextUtils.isEmpty(info.getUrl())){
				return;
			}
			Intent intent = new Intent();
			intent.putExtra(HttpKeys.KEY_APPURL, info.getUrl());
			intent.putExtra(HttpKeys.KEY_FLAG,1);
			intent.setClass(this.getActivity(), WebViewActivity.class);
			getActivity().startActivity(intent);
		}

	}

	public void setFocusedPosition(int pos) {
		LogUtil.d(TAG, "--> setFocusedPosition() position = " + pos);
		focusedPos = pos;
	}

	public int boolFlag() {
		return flag;
	}

	public boolean isAtTop() {
		if(flag==0){
			if (focusedPos < mPosterList.size()) {
				LogUtil.d(TAG, "--> isAtTop()  focusedPos="+focusedPos);
				//				HomepagecontentEdu info = mPosterList.get(focusedPos);

				for(HomepagecontentEdu positionEdu : mPosterList){
					if(positionEdu.getPosition() == focusedPos){
						LayoutEdu seat = positionEdu.getSeat();
						LogUtil.d(TAG, "--> isAtTop()  seat = (" + seat.getRow()+","+seat.getCol()+")");
						if (seat.getRow()==1) {
							LogUtil.d(TAG, "--> isAtTop()  seat.getRow() = " + seat.getRow());
							return true;
						}
					}
				}

			}
		}else{
			return true;
		}

		return false;
	}


	public boolean isAtRight(){
		if(flag==0){
			return isAtRight;
		}
		return false;
	}

	@Override
	public void onClick(View v) {

		if (info != null) {
			postClick(info);
		}

	}

	HomepagecontentEdu	info;


	@Override
	public void onFocusChange(View v, boolean hasFocus) {
		LogUtil.d(TAG, "--> onFocusChange() hasFocus = " + hasFocus);

		if (v.getTag() != null && v.getTag() instanceof HomepagecontentEdu) {
			info = (HomepagecontentEdu) v.getTag();
			if (hasFocus) {
				setFocusedPosition(info.getPosition());
			}
		}

		if (hasFocus) {
			LogUtil.d(TAG, "--> onFocusChange() hasFocus =  is true");
			LogUtil.d(TAG, "--> onFocusChange()  seat = (" + info.getSeat().getRow()+","+info.getSeat().getCol()+")");

			//			ScaleItemAnim anim = new ScaleItemAnim();
			//			anim.setParams(1.0F, 1.1F, 1.0F, 1.1F, 100L);
			//			v.startAnimation(anim.getAnimation());
		}
		else {
			LogUtil.d(TAG, "--> onFocusChange() hasFocus =  is false");

			//			ScaleItemAnim anim = new ScaleItemAnim();
			//			anim.setParams(1.1F, 1.0F, 1.1F, 1.0F, 0L);
			//			v.startAnimation(anim.getAnimation());
		}
	}

	public class JSInterface {
		private Context	mContext;

		public JSInterface(Context c) {
			mContext = c;
		}

		@JavascriptInterface
		public void appDetail(int no, String tag, String appID) {
			LogUtil.d(TAG, "appDetail");
			ToAppDetail(appID);
		}

		private void ToAppDetail(String appID) {
			try {

				if (AppUtils.isPkgExist(getActivity(), "com.ihome.android.market2")) {
					Intent intent = new Intent("com.ihome.android.market2.DetailActivity");
					intent.addCategory(Intent.CATEGORY_DEFAULT);
					intent.putExtra(HttpKeys.KEY_APPID, Integer.parseInt(appID));//测试数据,"765"
					startActivity(intent);
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

	public void loadSpecUrl(String url) {
		LogUtil.d(TAG, "url = " + url);
		specUrl = url;
		if (specUrl == null || specUrl.trim().equals("")) {
			return;
		}
		webView.loadUrl(specUrl);
	}

	private void startVideoPlay(String url) {

		Message msg = new Message();
		msg.obj = url;
		msg.what = MSG_VIDEO_PLAY;
		mHandler.sendMessageDelayed(msg, 800);
	}

	@SuppressWarnings("deprecation")
	private void initVideo() {
		if (mSurfaceView == null)
			return;
		if (mPlayer == null) {
			mPlayer = IPTVPlayer.Instance();
		}
		mSurfaceView.getHolder().setFormat(PixelFormat.TRANSPARENT);
		mSurfaceView.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
		mSurfaceView.getHolder().addCallback(new SurfaceHolder.Callback() {
			@Override
			public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
				if (null != holder.getSurface()) {
					mSurfaceHolder = holder;
					if (mSurfaceWidth != width || mSurfaceHeight != height) {
						mVideoInitialized = false;
						mSurfaceWidth = width;
						mSurfaceHeight = height;
					}
					initPlayer();

					if (mNeedStartPlay) {
						mNeedStartPlay = false;
						VideoRetryTime = 0;
						mPlayer.setLive(isLive);
						mPlayer.resume();
						Log.i("test", "onResume2");
					}
				}
			}

			@Override
			public void surfaceCreated(SurfaceHolder holder) {
				// TODO Auto-generated method stub

			}

			@Override
			public void surfaceDestroyed(SurfaceHolder holder) {
				mSurfaceHolder = null;
				mSurfaceWidth = -1;
				mSurfaceHeight = -1;
				//				releasePlayer();
				Log.d(TAG, "surfaceDestroyed > to stopPlayer");
				stopPlayer();
			}
		});

		startVideoPlay(playUrl);
	}

	private void initPlayer() {

		//		if (mSurfaceHolder != null && mSurfaceHolder.getSurface() != null && mSurfaceWidth > 0 && mSurfaceHeight > 0 && !mVideoInitialized) {
		if (mSurfaceHolder != null && mSurfaceHolder.getSurface() != null && mSurfaceWidth > 0 && mSurfaceHeight > 0) {
			Log.i("test", "initPlayer");


			if (mVideoInitialized == false) {
				mPlayer.initialize();
				mVideoInitialized = true;
				mPlayerReleased = false;
			}
			mPlayer.setSurface(mSurfaceHolder.getSurface());

			int w = mPlayer.getSystemWidth();
			int h = mPlayer.getSystemHeight();

			Log.i("test", "w = " + w + "\th = " + h);
			mPlayer.setScrHW(w, h);

			int[] location = new int[2];
			mSurfaceView.getLocationOnScreen(location);

			/*			mPlayer.setVideoWindow((int) (location[0] * 1.5 + 0.5),
								(int) (location[1] * 1.5 + 0.5),
								(int) (mSurfaceWidth * 1.5 + 0.5),
								(int) (mSurfaceHeight * 1.5 + 0.5));*/
			Log.d(TAG, "location[0] = " + location[0] + "\tlocation[1] = " + location[1] + "\tmSurfaceWidth  = " + mSurfaceWidth + "\tmSurfaceHeight = " + mSurfaceHeight);
			//gy:replace up with following codes for video window right more
			mPlayer.setVideoWindow((int) location[0], (int) location[1], (int) (mSurfaceWidth), (int) (mSurfaceHeight));
			mPlayer.setAudioBalance(0);

		}
	}

	private void releasePlayer() {
		Log.d(TAG, " to releasePlayer");
		IPTVPlayer.setActivityPaused(false);
		if (mPlayerReleased) {
			Log.d(TAG, " releasePlayer > mPlayerReleased == true");
			return;
		}
		if(mPlayer!=null){
			mPlayer.setLive(isLive);
			mPlayer.stop();
			mPlayer.release();
			mPlayer = null;
			mVideoInitialized = false;
			mNeedStartPlay = true;
			mPlayerReleased = true;
			Log.d(TAG, "releasePlayer over");
		}
		
	}

	private void stopPlayer() {
		Log.d(TAG, " to stopPlayer");
		mNeedStartPlay = true;
		if(mPlayer == null){
			Log.d(TAG, "stopPlayer >  mPlayer == null");
		}else{
			mPlayer.setLive(isLive);
			mPlayer.stop();
		}
	}

	@Override
	public void onPause() {
		super.onPause(); 
		Log.d(TAG, "onPause > to stopPlayer");
		stopPlayer();
		/*		if (mPlayerReleased == false) {
					Log.d(TAG, " onPause() > releasePlayer");
					releasePlayer();
				}*/
		Log.d(TAG, " onPause()");
	}

	@Override
	public void onStop() {
		super.onStop();
		Log.d(TAG, " onStop()");
	}

	@Override
	public boolean onKey(View v, int keyCode, KeyEvent event) {
		LogUtil.d(TAG, "------>onKey()--v.getId()=="+v.getId());
		if(v.getId()== R.id.img8 || v.getId()== R.id.surface_frame || (active_area.hasFocus() &&v.getId()==active_area.getId())){
			isAtRight = true;
		}else{
			isAtRight = false;
		}
		return false;
	}
	@Override
	public void onDestroy() {
		// TODO Auto-generated method stub
		LogUtil.d(TAG, " --> onDestroy()");
		super.onDestroy();
		if (mPlayerReleased == false) {
			releasePlayer();
		}
	}
}
